{include file="Public:header" /}
<style>

	.pagination a{
	    background-color: #f4f4f4;
	    z-index: 2;
		border:1px solid #000;
	    border-color: rgb(221, 221, 221);
		padding: 4px 10px;
		margin:0px 3px;
		border-radius:10%;
	}
	.form-control{
		font-size: 12px;
	}
</style>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>奖品列表</h5>
						<div class="ibox-tools">
						<a href="{:U('Prize/prizeList')}" class="btn btn-primary">刷新</a>
						</div>
					</div>
					<div class="ibox-content">
						<div class="row">
						<div class="col-sm-3">
							<a href="__URL__/addPrize" class="btn btn-primary">
								<span class="fa fa-plus"></span>
								添加奖品
							</a>
						</div>
						<form class="form-inline" action="__URL__/prizeList" method="post">
								<div class="col-sm-9">
		                                <div class="input-group col-sm-4  pull-right">
			                                    <input type="text" name="prize_name" placeholder="请输入奖品名称" class="input-sm form-control"> 
			                                    <span class="input-group-btn">
			                                      <button type="submit" class="btn btn-sm btn-primary"> 搜索</button>
			                                    </span>
		                                </div>

		                                <!--<div class="input-group col-sm-2 pull-right">
											 <select name="prize_type" class="input-sm form-control">
											 	<option value="">请选择奖品类型</option>
		                                        <option value="1">现金抵用券</option>
		                                        <option value="2">实物兑换券</option>
		                                        <option value="4">商品兑换券</option>
		                                    </select>
                                    	</div>-->
	                            </div>
	                     </form>  
						</div>
						<br />
						<div class="table-responsive">
						<form action="__URL__/deleteAllPrize" method="post" >	
							<table class="table table-bordered table-hover"
								id="categoryTable">
								<thead>
									<tr style="background: #f9f9f9;">
									<th><input onclick="all_check()" type="checkbox" /></th>
									<!--<th height="40">奖品类型</th>-->
									<!--<th>券名</th>-->
									<!--<th>价值</th>-->
									<!-- <th>商品最低金额</th> -->
									<th>奖品名称</th>
									<!-- <th>实物货号</th> -->
									<th>奖品数量</th>
									<th>剩余数量</th>
									<!--<th>中奖概率</th>-->
									<!--<th>每天最多中奖数量</th>-->
									<th>启用奖品</th>
									<!--<th>是否包邮</th>-->
									<!-- <th>备注</th> -->
									<!--<th>添加时间</th>-->
									<!--<th>红包使用时间</th>-->
									<!--<th>红包过期时间</th>-->
									<!--<th>签名</th>-->
									<th width="100">操作</th>
									</tr>
								</thead>
								<tbody>
									{foreach name="rule" item="rule"}
									<tr>
									<td><input type="checkbox" name="rule_id[]" value="{$rule['p_id']}" /></td>
									<!--<td>
										{if condition="$rule['prize_type'] eq 1"}
											现金抵用券
										{elseif condition="$rule['prize_type'] eq 2"/}
											实物兑换券
											{elseif condition="$rule['prize_type'] eq 4"/}
											商品兑换券
										{else/}
											谢谢参与
										{/if}
									</td>-->
									<!--<td>{$rule['voucher_name']}</td>-->
									<!--<td>{$rule['type_momey']}</td>-->
									<!-- <td>{$rule['min_goods_amount']}</td> -->
									<td>{$rule['prize_name']}</td>
									<!-- <td>{$rule['goods_sn']}</td> -->
									<td>{$rule['prize_num']}</td>
									<td>{$rule['surplus_num']}</td>
									<!--<td>{$rule['rate']}%</td>-->
									<!--<td>{$rule['max_winning']}</td>-->
									<td>{if condition="$rule['status'] eq 1"}是{else/}否{/if}</td>
									<!--<td>{if condition="$rule['is_shipping'] eq 1"}是{else/}否{/if}</td>-->
									<!-- <td>{$rule['note']}</td> -->
									<!--<td>{$rule['add_time']|date="Y-m-d H:i:s",###}</td>-->
									<!--<td>{$rule['use_start_date']|date="Y-m-d H:i:s",###}</td>-->
									<!--<td>{$rule['use_end_date']|date="Y-m-d H:i:s",###}</td>-->
									<!--<td>{$rule['signature']}</td>-->
										<td class="center">
											<div class="dropdown">
												<button class="btn btn-primary dropdown-toggle"
													type="button" id="dropdownMenu1" data-toggle="dropdown"
													aria-haspopup="true" aria-expanded="true">
													操作
													<span class="caret"></span>
												</button>
												<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
													<li>
														<a role="button" class="btn btn-primary"
															style="margin-bottom: 0px;" 
															href="__URL__/editPrize?p_id={$rule['p_id']}">
															<span class="fa fa-edit"></span>
															修改
														</a>
													</li>
													<li>
														<a role="button" class="btn btn-danger"
															style="margin-bottom: 0px;"
															onclick="deletePrize(this,{$rule['p_id']})" href="#">
															<span class="fa fa-trash-o"></span>
															删除
														</a>
													</li>
												</ul>
											</div>
										</td>
									</tr>
									{/foreach}
								</tbody>
							</table>
							
							<div style="padding-left:0px;" class="col-sm-3 text-left">
								<button tpye="submit" class="btn btn-danger">删除</button>
							</div>
							</form>
							<div class="col-sm-12 text-center">
								<nav aria-label="Page navigation">
								  <ul class="pagination">
								    {$page}
								  </ul>
								</nav>
							</div>
						</div>
						
					</div>
				</div>
			</div>
		</div>
	</div>
<script>
var h=1;
function all_check(){
	if(h==1){
		$("input[name='rule_id[]']").each(function() {  
	         $(this).prop("checked", true); 
	    }); 
		h=2;
	}else if(h==2){
		$("input[name='rule_id[]']").each(function() { 
            $(this).prop("checked", false); 
    	}); 
		h=1;
	}
}
</script>


<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
		<div class="modal-content">
		<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
						</button>
						<h4 class="modal-title" id="myModalLabel">添加商品</h4>
						</div>
						<div class="modal-body">
						<!-- class都是bootstrap定义好的样式，验证是根据input中的name值 -->
						<form action="__URL__/addShop" method="post" id="defaultForm">

						<div class="form-group">
						<label for="categoryName">商品名称</label>
						<input type="text" name="shop_name" style="border-radius: 4px;"
								id="categoryName" class="form-control" />
								</div>

								<div class="form-group">
								<label for="categoryTitle">商品地址</label>
								<input type="text" name="shop_address" style="border-radius: 4px;"
								id="categoryTitle" class="form-control" />
								</div>

								<div class="form-group">
								<label for="categoryKeywords">商品电话</label>
								<input type="text" name="shop_tel" style="border-radius: 4px;"
								id="categoryKeywords" class="form-control" />
								</div>

								<div class="form-group">
								<label for="categoryDescription">商品描述</label>
								<textarea name="shop_description" style="border-radius: 4px;"
								class="form-control" id="categoryDescription" /></textarea>
								</div>

						<div class="form-group">
								<label for="shopTel">地铁地址</label>
										<input type="text" name="metro_address" style="border-radius: 4px;"
										id="shopTel" class="form-control" />
										</div>

						<div class="form-group">
								<label for="shopTel">商品坐标</label>
										<input type="text" name="shop_coord" style="border-radius: 4px;"
										id="shopTel" class="form-control" />
										</div>

						<div class="modal-footer" id="parent_id">
								<button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>
										<button type="submit" class="btn btn-primary">提交</button>
										</div>
										</form>
										</div>
										</div>
		</div>
	</div>
	<!-- Modal -->

	{include file="Public:footer" /}

	<script>
$(document).ready(function() {
    /**
     * 下面是进行插件初始化
     * 你只需传入相应的键值对
     * */
    $('#defaultForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {/*输入框不同状态，显示图片的样式*/
            	  valid: 'glyphicon glyphicon-ok',
                  invalid: 'glyphicon glyphicon-remove',
                  validating: 'glyphicon glyphicon-refresh'
            },
            fields: {/*验证*/
            	shop_name: {/*键名username和input name值对应*/
                    message: '商品名称验证失败',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '商品名称不能为空'
                        },
                        stringLength: {/*长度提示*/
                            min: 2,
                            max: 30,
                            message: '商品名称长度必须在2到30之间'
                        }/*最后一个没有逗号*/
                    }
                },
                shop_address: {/*键名username和input name值对应*/
                    message: '商品地址验证失败',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '商品地址不能为空'
                        },
                        stringLength: {/*长度提示*/
                            min: 2,
                            max: 30,
                            message: '商品地址长度必须在2到30之间'
                        }/*最后一个没有逗号*/
                    }
                },
                shop_tel: {/*键名username和input name值对应*/
                    message: '商品电话验证失败',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '商品电话不能为空'
                        },
                        stringLength: {/*长度提示*/
                            min: 2,
                            max: 30,
                            message: '商品电话长度必须在2到30之间'
                        }/*最后一个没有逗号*/
                    }
                },
                shop_description: {/*键名username和input name值对应*/
                    message: '商品描述验证失败',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '商品描述不能为空'
                        },
                        stringLength: {/*长度提示*/
                            min: 2,
                            max: 30,
                            message: '商品描述长度必须在2到30之间'
                        }/*最后一个没有逗号*/
                    }
                },
                shop_coord:{/*键名username和input name值对应*/
                    message: '商品坐标验证失败',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '商品坐标不能为空'
                        },
                        stringLength: {/*长度提示*/
                            min: 2,
                            max: 30,
                            message: '商品坐标长度必须在2到30之间'
                        }/*最后一个没有逗号*/
                    }
                },
                metro_address:{/*键名username和input name值对应*/
                    message: '地铁地址验证失败',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '地铁地址不能为空'
                        },
                        stringLength: {/*长度提示*/
                            min: 2,
                            max: 30,
                            message: '地铁地址长度必须在2到30之间'
                        }/*最后一个没有逗号*/
                    }
                }
               
            }
            // 还有一个比较常用的就是submitHandler属性，它对应着提交按钮的事件方法。
            // submitHandler: function (validator, form, submitButton) {
                //alert("submit");
               /*  var menu_name = $("input[name='menu_name']").val();
                var link = $("input[name='link']").val();
                var ico = $("input[name='ico']").val();
                $.ajax({
                    url : '__URL__/addMenu',
                    type : 'get',
                    data : {'menu_name' : menu_name, 'link' : link, 'ico':ico},
                    dataType : 'json',
                    success : function(data){
                      alert(data.message);
                    }
                }); */
           // }
        });
});

//修改菜单
function editGroup(obj){
	var group_id = $(obj).attr('group_id');
	var group_title = $(obj).attr('group_title');
	$('#myModal').modal('show');
	$("#defaultForm").attr('action','__URL__/editUserGroup?id='+group_id);
	$("input[name='title']").val(group_title);
}

// window.onload=setTotal();	

//删除
function deletePrize(obj,p_id){
	layer.confirm('确定要删除数据吗',{btn:['确认','取消'], icon:3, closeBtn: 2 },function(index){
		$.ajax({
			url : '__URL__/deletePrize',
			data : {'p_id':p_id},
			type : 'get',
			dataType : 'json',
			async : false,   //取消同步，执行完之后再往下执行
			success : function(data){
				if(data.status == 1){				
					layer.msg(''+data.message+'',{icon:2,time:1000});
					$(obj).parent('li').parent('ul').parent('div').parent('td').parent('tr').remove();
				}else if(data.status == 2){
					layer.msg(''+data.message+'',{icon:1,time:1000});
				}
			}
		});
	});	
}
</script>


</body>
</html>
